package cn.yangliu.task.handler;

import cn.yangliu.task.entity.Task;
import cn.yangliu.task.entity.TaskVo;
import cn.yangliu.task.utils.TransformDataUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author 杨柳
 * @date 2019-04-09
 */
public class TaskUpdateHandlerImpl implements TaskUpdateHandler {


    @Autowired
    private TaskPublisher taskPublisher;

    @Override
    public void cancleTask(Task task) {
        TaskVo taskVo = TransformDataUtils.getTransformData(task);
        taskPublisher.sendMessage(TaskPublisher.PUBLISH_TYPE_CANCLE, taskVo);
    }

    @Override
    public void createTask(Task task) {
        TaskVo taskVo = TransformDataUtils.getTransformData(task);
        taskPublisher.sendMessage(TaskPublisher.PUBLISH_TYPE_CREATE, taskVo);
    }

    @Override
    public void restartTask(Task task) {
        TaskVo taskVo = TransformDataUtils.getTransformData(task);
        taskPublisher.sendMessage(TaskPublisher.PUBLISH_TYPE_RESTART, taskVo);
    }
}
